YZYZ.Admin.Region.editRegionWin 	= null;
YZYZ.Admin.Region.editRegionForm 	= null;
YZYZ.Admin.Region.editRegionName 	= null;
YZYZ.Admin.Region.editCB 			= null;
YZYZ.Admin.Region.showEditWin = function(){
	if(!YZYZ.Admin.Region.editRegionWin){
		YZYZ.Admin.Region.editCB = new Ext.form.ComboBox({  
	         id: 'editLevel', 
	         name:'editLevel', 
	         allowBlank: false,  
	         fieldLabel: "显示级别",  
	         hiddenName: 'hidEditLevel',  
	         displayField: 'name',  
	         valueField: 'id',  
	         typeAhead: true,  
	         triggerAction: 'all',  
	         store: YZYZ.levelData.levelStore,  
	         mode: 'local',
	         width:200 ,
	         editable:false
 		});
		YZYZ.Admin.Region.editRegionName = new Ext.form.TextField({
			width:200,
			id:'editName',
			fieldLabel:'名称',
			maxLength:20
		});
		YZYZ.Admin.Region.editRegionName.on("render",YZYZ.appendRedStar);
		YZYZ.Admin.Region.editRegionForm = new Ext.form.FormPanel({
			labelWidth:100,
			labelAlign:'right',
			region:'center',
			bodyStyle:'padding-top:20px',
			height:200,
			width:400,
			items:[
				YZYZ.Admin.Region.editRegionName,
				YZYZ.Admin.Region.editCB,
				{
					xtype:'textarea',
					width:200,
					id:'editDescription',
					fieldLabel:'描述',
					maxLength:100
				}
			]
		});
		YZYZ.Admin.Region.editRegionWin = new Ext.Window({
			title:'编辑组',
			width:400,
			height:250,
			layout:'border',
			modal:true,
			closable:true,
			closeAction:'hide',
			items:[YZYZ.Admin.Region.editRegionForm],
			buttons:[{
				text:'提交',
				handler:YZYZ.Admin.Region.editSubmit
			},{
				text:'取消',
				handler:function(){YZYZ.Admin.Region.editRegionWin.hide();}
			}]
			
		});
	}
	YZYZ.Admin.Region.editRegionWin.show();
	YZYZ.Admin.Region.editRegionName.setValue(YZYZ.Admin.Region.gridPanel.getSelectionModel().getSelected().get("name"));
	Ext.getCmp("editDescription").setValue(YZYZ.Admin.Region.gridPanel.getSelectionModel().getSelected().get("description"));
	Ext.getCmp("editLevel").setValue(YZYZ.Admin.Region.gridPanel.getSelectionModel().getSelected().get("level"));
};
YZYZ.Admin.Region.editSubmit = function(){
	var name = Ext.getCmp("editName").getValue();
	var description=Ext.getCmp("editDescription").getValue();
	if(Ext.isEmpty(name)){
		YZYZ.Curtain.alert("请填写名称");
		Ext.getCmp("editName").markInvalid();
		return;
	}
	if(name.length > 20) {
		YZYZ.Curtain.alert("名称长度不能超过20");
		Ext.getCmp("editName").markInvalid();
		return;
	}
	if(description.length > 100){
		YZYZ.Curtain.alert("描述的内容长度不能超过100");
		Ext.getCmp("editDescription").markInvalid();
		return;
	}
	YZYZ.Curtain.msg("系统处理中....");
	Ext.Ajax.request( {
		url		: Ext.get("updateUrl").dom.value,
		timeout	: 30000,
		method	: 'POST',
		params	: {
			name 		:  name,
			description	: description,
			regionId    : YZYZ.Admin.Region.gridPanel.getSelectionModel().getSelected().get("id"),
			level		: Ext.getCmp("editLevel").getValue()
		},
		success : function(result, request) {
			result = Ext.util.JSON.decode(result.responseText);
			if(result.code == YZYZ.success){
				YZYZ.Curtain.msg("修改成功");
				YZYZ.Admin.Region.gridPanel.getSelectionModel().getSelected().set("name", name);
			    YZYZ.Admin.Region.gridPanel.getSelectionModel().getSelected().set("description", description);
			    YZYZ.Admin.Region.gridPanel.getSelectionModel().getSelected().set("level", Ext.getCmp("editLevel").getValue());
			    
				YZYZ.Admin.Region.gridPanel.getStore().commitChanges();
				YZYZ.Admin.Region.editRegionWin.hide();			
			}
			else {
				YZYZ.Curtain.alert(result.message);
			}
		},
		failure : function(result, request) {
			YZYZ.Curtain.alert("操作失败！程序错误或网络故障");
		}
	});	
};